#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=50000, maxk=17;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

void getSa(char *s, int n, int *sa, int *rank) {
  int pos[2*maxn+3], temp[2*maxn+3];
  for (int i=1; i<=n; i++) {
    pos[s[i]-'#']++;
  }
  for (int i=1; i<=257; i++) {
    pos[i] += pos[i-1];
  }
  for (int i=1; i<=n; i++) {
    sa[pos[s[i]-'#']--]=i;
  }
  for (int i=1; i<=n; i++) {
    rank[sa[i]] = rank[sa[i-1]] + (s[sa[i]]!=s[sa[i-1]]);
  }

  for (int len=1; len<n; len=len*2) {
    for (int i=0; i<=n; i++) {
      pos[i]=0;
      temp[i]=sa[i];
    }
    for (int i=1; i<=n; i++) {
      pos[rank[i]]++;
    }
    for (int i=1; i<=n; i++) {
      pos[i] += pos[i-1];
    }
    for (int i=n; i>0; i--) {
      if (temp[i]>len) {
	sa[pos[rank[temp[i]-len]]--] = temp[i]-len;
      }
    }
    for (int i=n-len+1; i<=n; i++) {
      sa[pos[rank[i]]--] = i;
    }
    temp[sa[1]]=1;
    for (int i=2; i<=n; i++) {
      if (rank[sa[i-1]]==rank[sa[i]] && ((sa[i-1]+len>n && sa[i]+len>n) || ((sa[i-1]+len<=n && sa[i]+len<=n) && rank[sa[i-1]+len]==rank[sa[i]+len]))) {
	temp[sa[i]] = temp[sa[i-1]];
      } else {
	temp[sa[i]] = temp[sa[i-1]]+1;
      }
    }
    for (int i=1; i<=n; i++) {
      rank[i]=temp[i];
    }
  }
}

void getHeight(char *s, int n, int *sa, int *rank, int *h, int *height) {
  for (int i=1; i<=n; i++) {
    if (rank[i]==1) {
      h[i]=0;
    } else {
      h[i] = h[i-1]>0 ? h[i-1]-1 : 0;
      for (; s[i+h[i]]==s[sa[rank[i]-1]+h[i]]; h[i]++);
    }
    height[rank[i]]=h[i];
  }
}

void initRMQ(int *a, int n, int rmq[][maxk+1]) {
  for (int i=1; i<=n; i++) {
    rmq[i][0]=a[i];
  }
  for (int i=1; i<=maxk; i++) {
    for (int j=1; j<=n; j++) {
      if (j+(1<<(i-1))<=n) {
	rmq[j][i] = min(rmq[j][i-1], rmq[j+(1<<(i-1))][i-1]);
      } else {
	rmq[j][i] = rmq[j][i-1];
      }
    }
  }
}

int getMin(int l, int r, int rmq[][maxk+1]) {
  if (l>r) {
    int temp;
    temp=l, l=r, r=temp;
  }
  int i;
  for (i=maxk; i>=0 && (1<<i)>(r-l+1); i--);
  return min(rmq[l][i], rmq[r-(1<<i)+1][i]);
}

int main() {
#ifdef DEBUG
  freopen("3337.in", "r", stdin);
  freopen("3337.out", "w", stdout);
#endif

  static char a[maxn+2], b[maxn+2], c[2*maxn+3];
  int lena, lenb, lenc;
  scanf("%s %s", a+1, b+1);
  lena=strlen(a+1), lenb=strlen(b+1);
  for (int i=1; i<=lena; i++) {
    c[i]=a[i];
  }
  c[1+lena]='%';
  for (int i=1; i<=lenb; i++) {
    c[1+lena+i]=b[i];
  }
  lenc=lena+lenb+2;
  c[lenc]='#';

  static int sa[2*maxn+3], rank[2*maxn+3], height[2*maxn+3], h[2*maxn+3], rmq[2*maxn+3][maxk+1];
  getSa(c, lenc, sa, rank);
  getHeight(c, lenc, sa, rank, h, height);
  initRMQ(height, lenc, rmq);

  int ans=0;
  for (int i=1; i<=lenb; i++) {
    int t;
    if (rank[1]<rank[lena+1+i]) {
      t=getMin(rank[1]+1, rank[lena+1+i], rmq);
    } else {
      t=getMin(rank[lena+1+i], rank[1], rmq);
    }
    if (2+t<=lena+1 && lena+i+t+2<=lenc) {
      if (rank[t+2]<rank[lena+i+t+2]) {
	ans = max(ans, t+1+getMin(rank[t+2]+1, rank[lena+i+t+2], rmq));
      } else {
	ans = max(ans, t+1+getMin(rank[lena+i+t+2]+1, rank[t+2], rmq));
      }
    } else {
      ans = max(ans, t);
    }
  }
  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
